package com.qdu.reducer;

import com.qdu.bean.RentCarBean;
import com.qdu.bean.bikeWritable;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class CountByYearReducer extends Reducer<bikeWritable, RentCarBean, Text, RentCarBean> {
    private RentCarBean resultBean = new RentCarBean();
    @Override
    protected void reduce(bikeWritable key, Iterable<RentCarBean> values, Context context) throws IOException, InterruptedException {
        int casual=0;
        int registered=0;
        int count=0;
        int sum=0;
        for (RentCarBean b :
                values) {
            casual+=b.getCasual();
            registered+=b.getRegistered();
            count+=b.getCount();
            sum++;
        }

        resultBean.set1(casual,registered,count);
        context.write(new Text(key.toString()),resultBean);
    }
}
